<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>STRATEGIC CONSTRUCTION:  Fichier source de /Users/pierre-loupbarazzutti/Desktop/svn/silverstarlif7/projet/src/Unite.c</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">STRATEGIC CONSTRUCTION
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Généré par Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Page&#160;principale</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Fichiers</span></a></li>
      <li><a href="dirs.html"><span>Répertoires</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>Liste&#160;des&#160;fichiers</span></a></li>
      <li><a href="globals.html"><span>Membres&#160;de&#160;fichier</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_unite_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Unite.c</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_unite_8c.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="_unite_8h.html">Unite.h</a>&quot;</span>
<a name="l00002"></a>00002 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00003"></a>00003 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00004"></a>00004 <span class="preprocessor">#include &lt;time.h&gt;</span>
<a name="l00005"></a>00005 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00006"></a>00006 
<a name="l00007"></a><a class="code" href="_unite_8h.html#a513f9afaf118a3c62f342145d7d4b876">00007</a> <span class="keywordtype">void</span> <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a> (<a class="code" href="structs_unite.html">Unite</a> * u,<span class="keyword">const</span> <span class="keywordtype">int</span> type ,<span class="keyword">const</span> <span class="keywordtype">int</span> equipe)
<a name="l00008"></a>00008 {
<a name="l00009"></a>00009         (*u).equipe = equipe;
<a name="l00010"></a>00010         (*u).type = type;
<a name="l00011"></a>00011         (*u).utilise = 1;
<a name="l00012"></a>00012         <span class="keywordflow">switch</span>(type) 
<a name="l00013"></a>00013         {
<a name="l00014"></a>00014 <span class="comment">/* Bucheron */</span>          
<a name="l00015"></a>00015                 <span class="keywordflow">case</span> 1:
<a name="l00016"></a>00016                         (*u).vie = 100;
<a name="l00017"></a>00017                         (*u).attaque = 0;
<a name="l00018"></a>00018                         (*u).defense = 0;       
<a name="l00019"></a>00019                         (*u).deplacement = 4;
<a name="l00020"></a>00020                         (*u).utilise = 1;
<a name="l00021"></a>00021                 <span class="keywordflow">break</span>;  
<a name="l00022"></a>00022         
<a name="l00023"></a>00023 <span class="comment">/* Pêcheur */</span>
<a name="l00024"></a>00024                 <span class="keywordflow">case</span> 2:
<a name="l00025"></a>00025                         (*u).vie = 100;
<a name="l00026"></a>00026                         (*u).attaque = 0;
<a name="l00027"></a>00027                         (*u).defense = 0;
<a name="l00028"></a>00028                         (*u).deplacement = 4;
<a name="l00029"></a>00029                         (*u).equipe = equipe;
<a name="l00030"></a>00030                         (*u).utilise = 1;
<a name="l00031"></a>00031                 <span class="keywordflow">break</span>;
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="comment">/* Infanterie 1 */</span>
<a name="l00034"></a>00034                 <span class="keywordflow">case</span> 3:
<a name="l00035"></a>00035                         (*u).vie = 100;
<a name="l00036"></a>00036                         (*u).attaque = 0.3;
<a name="l00037"></a>00037                         (*u).defense = 0.1;
<a name="l00038"></a>00038                         (*u).deplacement = 4;
<a name="l00039"></a>00039                         (*u).equipe = equipe;
<a name="l00040"></a>00040                         (*u).utilise = 1;
<a name="l00041"></a>00041                 <span class="keywordflow">break</span>;
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 <span class="comment">/* Infanterie 2 */</span>
<a name="l00044"></a>00044                 <span class="keywordflow">case</span> 4:
<a name="l00045"></a>00045                         (*u).vie = 100;
<a name="l00046"></a>00046                         (*u).attaque = 0.5;
<a name="l00047"></a>00047                         (*u).defense = 0.2;
<a name="l00048"></a>00048                         (*u).deplacement = 3;
<a name="l00049"></a>00049                         (*u).equipe = equipe;
<a name="l00050"></a>00050                         (*u).utilise = 1;
<a name="l00051"></a>00051                 <span class="keywordflow">break</span>;
<a name="l00052"></a>00052                 
<a name="l00053"></a>00053 <span class="comment">/* Infanterie 3 */</span>
<a name="l00054"></a>00054                 <span class="keywordflow">case</span> 5:
<a name="l00055"></a>00055                         (*u).vie = 100;
<a name="l00056"></a>00056                         (*u).attaque = 0.8;
<a name="l00057"></a>00057                         (*u).defense = 0.4;
<a name="l00058"></a>00058                         (*u).deplacement = 3;
<a name="l00059"></a>00059                         (*u).equipe = equipe;
<a name="l00060"></a>00060                         (*u).utilise = 1;
<a name="l00061"></a>00061                 <span class="keywordflow">break</span>;
<a name="l00062"></a>00062                 
<a name="l00063"></a>00063                 <span class="keywordflow">default</span> : 
<a name="l00064"></a>00064                         (*u).vie = 0;
<a name="l00065"></a>00065                         (*u).attaque = 0;
<a name="l00066"></a>00066                         (*u).defense = 0;
<a name="l00067"></a>00067                         (*u).deplacement = 0;
<a name="l00068"></a>00068                         (*u).equipe = equipe;
<a name="l00069"></a>00069                         (*u).utilise = 1;       
<a name="l00070"></a>00070                 <span class="keywordflow">break</span>;
<a name="l00071"></a>00071         }
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 
<a name="l00074"></a><a class="code" href="_unite_8h.html#a2df5f84d40b0cfdc35a2e9e780f59429">00074</a> <span class="keywordtype">void</span> <a class="code" href="_unite_8c.html#a2df5f84d40b0cfdc35a2e9e780f59429">DestructionUnite</a>(<a class="code" href="structs_unite.html">Unite</a> * u)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076         (*u).type = 0;
<a name="l00077"></a>00077         (*u).vie = 0;
<a name="l00078"></a>00078         (*u).attaque = 0;
<a name="l00079"></a>00079         (*u).defense = 0;
<a name="l00080"></a>00080         (*u).deplacement = 0;
<a name="l00081"></a>00081         (*u).equipe = 0;
<a name="l00082"></a>00082         (*u).utilise = 0;
<a name="l00083"></a>00083 }
<a name="l00084"></a>00084 
<a name="l00085"></a><a class="code" href="_unite_8h.html#a1bd5d8c5bd17393555871d8671e3c080">00085</a> <span class="keywordtype">void</span> <a class="code" href="_unite_8c.html#a1bd5d8c5bd17393555871d8671e3c080">ModifierUtiliseUnite</a> (<a class="code" href="structs_unite.html">Unite</a> * u, <span class="keywordtype">int</span> utilise)
<a name="l00086"></a>00086 {
<a name="l00087"></a>00087 assert(utilise ==0 || utilise == 1);
<a name="l00088"></a>00088         (*u).utilise = utilise;
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 
<a name="l00091"></a><a class="code" href="_unite_8h.html#a9d049eae54ca03f0cffb6ba92cb2f468">00091</a> <span class="keywordtype">int</span> <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a> (<a class="code" href="structs_unite.html">Unite</a> * u1, <a class="code" href="structs_unite.html">Unite</a> * u2)
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093         <span class="keywordtype">int</span> ajout = 0;
<a name="l00094"></a>00094         <span class="keywordtype">int</span> attaque1 ;
<a name="l00095"></a>00095         <span class="keywordtype">int</span> attaque2 = (*u2).vie * (*u2).attaque - (*u1).vie * (*u1).defense;
<a name="l00096"></a>00096         srand(time(NULL));
<a name="l00097"></a>00097         ajout = (rand() % 15); <span class="comment">/* Bonus d&#39;attaque pour le premier attaquant */</span>
<a name="l00098"></a>00098         attaque1 = (*u1).vie * (*u1).attaque + ajout - (*u2).vie * (*u2).defense;
<a name="l00099"></a>00099         
<a name="l00100"></a>00100         <span class="keywordflow">if</span> (attaque1 &lt; 1)
<a name="l00101"></a>00101         {
<a name="l00102"></a>00102                 attaque1 = 1;
<a name="l00103"></a>00103         }
<a name="l00104"></a>00104         <span class="keywordflow">if</span> (attaque2 &lt; 1)
<a name="l00105"></a>00105         {
<a name="l00106"></a>00106                 <span class="keywordflow">if</span>( (*u2).type == 1 || (*u2).type == 2)
<a name="l00107"></a>00107                 {
<a name="l00108"></a>00108                         attaque2 = 0;
<a name="l00109"></a>00109                 }
<a name="l00110"></a>00110                 <span class="keywordflow">else</span>
<a name="l00111"></a>00111                 {
<a name="l00112"></a>00112                         attaque2 = 1;   
<a name="l00113"></a>00113                 }
<a name="l00114"></a>00114         }
<a name="l00115"></a>00115         
<a name="l00116"></a>00116         (*u2).vie = (*u2).vie - attaque1;
<a name="l00117"></a>00117         <span class="keywordflow">if</span> ((*u2).vie &lt;= 0)
<a name="l00118"></a>00118         {
<a name="l00119"></a>00119                 <span class="keywordflow">return</span> 1;
<a name="l00120"></a>00120         }
<a name="l00121"></a>00121         (*u1).vie = (*u1).vie - attaque2;
<a name="l00122"></a>00122         <span class="keywordflow">if</span> ((*u1).vie &lt;= 0)
<a name="l00123"></a>00123         {
<a name="l00124"></a>00124                 <span class="keywordflow">return</span> 2;
<a name="l00125"></a>00125         }
<a name="l00126"></a>00126         <span class="keywordflow">return</span> 0;
<a name="l00127"></a>00127 }
<a name="l00128"></a>00128 
<a name="l00129"></a><a class="code" href="_unite_8h.html#acb543d02e600f174b7914ebf72361922">00129</a> <span class="keywordtype">void</span> <a class="code" href="_unite_8c.html#acb543d02e600f174b7914ebf72361922">UniteTestRegression</a>()
<a name="l00130"></a>00130 {
<a name="l00131"></a>00131         <a class="code" href="structs_unite.html">Unite</a> *utest = (<a class="code" href="structs_unite.html">Unite</a>*)malloc(<span class="keyword">sizeof</span>(<a class="code" href="structs_unite.html">Unite</a>));
<a name="l00132"></a>00132         <a class="code" href="structs_unite.html">Unite</a> *utest2 = (<a class="code" href="structs_unite.html">Unite</a>*)malloc(<span class="keyword">sizeof</span>(<a class="code" href="structs_unite.html">Unite</a>));
<a name="l00133"></a>00133         <span class="keywordtype">int</span> testresult;
<a name="l00134"></a>00134 
<a name="l00135"></a>00135         <span class="comment">/* Vérification de la procédure InitialisationUnite */</span>
<a name="l00136"></a>00136         <span class="comment">/* Vérification si l&#39;unite est de type bûcheron et d&#39;équipe 0 */</span>
<a name="l00137"></a>00137         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 1, 0);
<a name="l00138"></a>00138         assert( (*utest).type == 1);
<a name="l00139"></a>00139         assert( (*utest).equipe == 0);
<a name="l00140"></a>00140         assert( (*utest).vie == 100);
<a name="l00141"></a>00141         assert( (*utest).attaque == 0);
<a name="l00142"></a>00142         assert( (*utest).defense == 0);
<a name="l00143"></a>00143         assert( (*utest).deplacement == 4);
<a name="l00144"></a>00144         assert( (*utest).utilise == 1);
<a name="l00145"></a>00145 
<a name="l00146"></a>00146         <span class="comment">/* Vérification si l&#39;unite est de type pêcheur */</span>
<a name="l00147"></a>00147         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 2, 0);
<a name="l00148"></a>00148         assert( (*utest).type == 2);
<a name="l00149"></a>00149         assert( (*utest).equipe == 0);
<a name="l00150"></a>00150         assert( (*utest).vie == 100);
<a name="l00151"></a>00151         assert( (*utest).attaque == 0);
<a name="l00152"></a>00152         assert( (*utest).defense == 0);
<a name="l00153"></a>00153         assert( (*utest).deplacement == 4);
<a name="l00154"></a>00154         assert( (*utest).utilise == 1);
<a name="l00155"></a>00155         
<a name="l00156"></a>00156         <span class="comment">/* Vérification si l&#39;unité est de type infanterie1 */</span>
<a name="l00157"></a>00157         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 3, 0);
<a name="l00158"></a>00158         assert( (*utest).type == 3);
<a name="l00159"></a>00159         assert( (*utest).equipe == 0);
<a name="l00160"></a>00160         assert( (*utest).vie == 100);
<a name="l00161"></a>00161         assert( (*utest).attaque == (<span class="keywordtype">float</span>)0.3);
<a name="l00162"></a>00162         assert( (*utest).defense == (<span class="keywordtype">float</span>)0.1);
<a name="l00163"></a>00163         assert( (*utest).deplacement == 4);
<a name="l00164"></a>00164         assert( (*utest).utilise == 1);
<a name="l00165"></a>00165         
<a name="l00166"></a>00166         <span class="comment">/* Vérification si l&#39;unité est de type Infanterie2 */</span>
<a name="l00167"></a>00167         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 4, 0);
<a name="l00168"></a>00168         assert( (*utest).type == 4);
<a name="l00169"></a>00169         assert( (*utest).equipe == 0);
<a name="l00170"></a>00170         assert( (*utest).vie == 100);
<a name="l00171"></a>00171         assert( (*utest).attaque == (<span class="keywordtype">float</span>)0.5);
<a name="l00172"></a>00172         assert( (*utest).defense == (<span class="keywordtype">float</span>)0.2);
<a name="l00173"></a>00173         assert( (*utest).deplacement == 3);
<a name="l00174"></a>00174         assert( (*utest).utilise == 1);
<a name="l00175"></a>00175         
<a name="l00176"></a>00176         <span class="comment">/* Vérification si l&#39;unité est de type Infanterie3 */</span>
<a name="l00177"></a>00177         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 5, 0);
<a name="l00178"></a>00178         assert( (*utest).type == 5);
<a name="l00179"></a>00179         assert( (*utest).equipe == 0);
<a name="l00180"></a>00180         assert( (*utest).vie == 100);
<a name="l00181"></a>00181         assert( (*utest).attaque == (<span class="keywordtype">float</span>)0.8);
<a name="l00182"></a>00182         assert( (*utest).defense == (<span class="keywordtype">float</span>)0.4);
<a name="l00183"></a>00183         assert( (*utest).deplacement == 3);
<a name="l00184"></a>00184         assert( (*utest).utilise == 1);
<a name="l00185"></a>00185         
<a name="l00186"></a>00186         <span class="comment">/* Vérification de la procédure ModifierUtiliseUnite */</span>
<a name="l00187"></a>00187         <a class="code" href="_unite_8c.html#a1bd5d8c5bd17393555871d8671e3c080">ModifierUtiliseUnite</a>(utest, 1);
<a name="l00188"></a>00188         assert( (*utest).utilise == 1);
<a name="l00189"></a>00189 
<a name="l00190"></a>00190         <span class="comment">/* Vérification de la procédure CombatUnite */</span>
<a name="l00191"></a>00191         <span class="comment">/* Test avec (attaque1 &lt; 1) et ((*utest).vie&gt;0)  */</span>
<a name="l00192"></a>00192         
<a name="l00193"></a>00193         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 3, 0);
<a name="l00194"></a>00194         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest2, 5, 1);
<a name="l00195"></a>00195         testresult = <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a>(utest, utest2);
<a name="l00196"></a>00196         assert( (*utest2).vie == 99);
<a name="l00197"></a>00197         assert( testresult == 0);
<a name="l00198"></a>00198         
<a name="l00199"></a>00199         <span class="comment">/* Test passant dans la boucle if (attaque2 &lt; 1) et ((*utest2).vie&gt;0 */</span>
<a name="l00200"></a>00200         
<a name="l00201"></a>00201         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 5, 0);
<a name="l00202"></a>00202         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest2, 3, 1);
<a name="l00203"></a>00203         testresult = <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a>(utest, utest2);
<a name="l00204"></a>00204         assert( (*utest).vie == 99);
<a name="l00205"></a>00205         assert( testresult == 0);
<a name="l00206"></a>00206         
<a name="l00207"></a>00207         <span class="comment">/* Test passant dans la boucle if ((*utest2).vie &lt; 0) */</span>
<a name="l00208"></a>00208         
<a name="l00209"></a>00209         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 5, 0);
<a name="l00210"></a>00210         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest2, 3, 1);
<a name="l00211"></a>00211         (*utest2).vie -= 50;
<a name="l00212"></a>00212         testresult = <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a>(utest, utest2);
<a name="l00213"></a>00213         assert( (*utest2).vie &lt;= 0);
<a name="l00214"></a>00214         assert( testresult == 1);
<a name="l00215"></a>00215         
<a name="l00216"></a>00216         <span class="comment">/* Test passant dans la boucle if ((*utest2).vie &lt; 0) */</span>
<a name="l00217"></a>00217         
<a name="l00218"></a>00218         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest, 3, 0);
<a name="l00219"></a>00219         <a class="code" href="_unite_8c.html#a513f9afaf118a3c62f342145d7d4b876">InitialisationUnite</a>(utest2, 5, 1);
<a name="l00220"></a>00220         (*utest).vie -= 50;
<a name="l00221"></a>00221         testresult = <a class="code" href="_unite_8c.html#a9d049eae54ca03f0cffb6ba92cb2f468">CombatUnite</a>(utest, utest2);
<a name="l00222"></a>00222         assert( (*utest).vie &lt;= 0);
<a name="l00223"></a>00223         assert( testresult == 2);
<a name="l00224"></a>00224 
<a name="l00225"></a>00225                 <span class="comment">/* Vérification de la procédure DestructionUnite */</span>
<a name="l00226"></a>00226         <a class="code" href="_unite_8c.html#a2df5f84d40b0cfdc35a2e9e780f59429">DestructionUnite</a>(utest);
<a name="l00227"></a>00227         assert( (*utest).type == 0);    
<a name="l00228"></a>00228         assert( (*utest).equipe == 0);
<a name="l00229"></a>00229         assert( (*utest).vie == 0);
<a name="l00230"></a>00230         assert( (*utest).attaque == 0);
<a name="l00231"></a>00231         assert( (*utest).defense == 0);
<a name="l00232"></a>00232         assert( (*utest).deplacement == 0);
<a name="l00233"></a>00233         assert( (*utest).utilise == 0);
<a name="l00234"></a>00234         <a class="code" href="_unite_8c.html#a2df5f84d40b0cfdc35a2e9e780f59429">DestructionUnite</a>(utest2);
<a name="l00235"></a>00235         
<a name="l00236"></a>00236         free(utest);
<a name="l00237"></a>00237         free(utest2);
<a name="l00238"></a>00238 }
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_unite_8c.html">Unite.c</a>      </li>

    <li class="footer">Généré le Jeudi Juin 7 2012 11:43:12 pour STRATEGIC CONSTRUCTION par
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
